//
//  FactoryDetailsViewController.m
//  MagicZhao
//
//  Created by hy002 on 2017/12/21.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "FactoryDetailsViewController.h"
#import "WorkDetailsViewController.h"
#import "SDCycleScrollView.h"
#import "FactoryModel.h"
#import "dailyImgModel.h"
#import "JobsModel.h"
#import "ScoringModel.h"
#import "CDZStarsControl.h"
#import <MapKit/MapKit.h>
#import "MyProductionLineTableViewCell.h"
#import "ProductionLineModel.h"
#import "ProduceMachinesModel.h"
#import "SetUpTimeViewController.h"
#import "ProduceLineDetailViewController.h"
#import "ProjectEditViewController.h"
#import "FeedBackViewController.h"
#import "ShareManager.h"
#import "LoginOrRegisterViewController.h"
#import "HYNavBaseViewController.h"
#import "AuthenticationViewController.h"

static NSString *cellPath = @"FactoryCell";
@interface FactoryDetailsViewController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate,CDZStarsControlDelegate>
{
    UIView *lineBottomV;
    UIView *setUpView;
    UIAlertController *alert;
}
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)SDCycleScrollView *cycleScrollView;
@property (nonatomic, assign)NSInteger infoType;
@property (nonatomic, strong)FactoryModel *factoryModel;
@property (nonatomic, strong)NSMutableArray *orderAry;
@property (nonatomic, strong)NSMutableArray *scoringAry;
@property (nonatomic, assign)NSInteger leftPage;
@property (nonatomic, assign)NSInteger rightPage;

@property (nonatomic, strong) UserModel *userModel;
@property (nonatomic, assign) BOOL isClick;
@property (nonatomic, strong) NSTimer *timer;
@end

@implementation FactoryDetailsViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    _isClick = NO;
    [self requestGetUserInfo];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    _infoType = 0;
    _leftPage = 0;
    _rightPage = 0;
    _orderAry = [NSMutableArray arrayWithCapacity:0];
    _scoringAry = [NSMutableArray arrayWithCapacity:0];
    [self creatUI];
    [self requestContractorDetail];
    [self requestRecruitmentNotice];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [_timer invalidate];//计时器停止
    _timer = nil;
}

- (void)creatUI
{
    self.view.backgroundColor = BacksColor;
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, -STATUSBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT+STATUSBAR_HEIGHT-SCREER_HeiX) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = BacksColor;
    [self.view addSubview:_tableview];
    UIView *heardView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 220*displayheight)];
    heardView.backgroundColor = [UIColor whiteColor];
    self.tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewHeaderData)];
    self.tableview.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreFootData)];
    self.tableview.mj_footer.automaticallyHidden = YES;
    self.tableview.estimatedRowHeight = 0;
    self.tableview.estimatedSectionHeaderHeight = 0;
    self.tableview.estimatedSectionFooterHeight = 0;
    if (@available(iOS 11.0, *)) {
        _tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    _tableview.estimatedRowHeight = 0;
    _tableview.estimatedSectionHeaderHeight = 0;
    _tableview.estimatedSectionFooterHeight = 0;
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 220*displayheight) delegate:self placeholderImage:nil];
    _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    _cycleScrollView.delegate = self;
    //是否自动轮播
    _cycleScrollView.autoScroll = YES;//是否自动轮播 bannerImageViewContentMode
    //图片样式
    _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    _cycleScrollView.clipsToBounds = YES;
    //分页样式
    _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    [heardView addSubview:_cycleScrollView];
    _tableview.tableHeaderView = heardView;

    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, STATUSBAR_HEIGHT, SCREEN_WIDTH, 60*displaywidth)];
    topView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:topView];
    
    UIButton *backBtn = [ZCControl createButtonWithFrame:CGRectMake(10*displaywidth, 10*displaywidth, 40*displaywidth, 40*displaywidth) ImageName:@"fh" Target:self Action:@selector(backAction) Title:nil Font:12.0];
    backBtn.backgroundColor = [UIColor clearColor];
    [topView addSubview:backBtn];
    
    UIButton *feedbackBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-50*displaywidth, 10*displaywidth, 40*displaywidth, 40*displaywidth) ImageName:@"sanged" Target:self Action:@selector(feedbackAction) Title:nil Font:12.0];
    feedbackBtn.backgroundColor = [UIColor clearColor];
    [topView addSubview:feedbackBtn];
    
    setUpView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-115*displaywidth, 50*displaywidth+STATUSBAR_HEIGHT, 100*displaywidth, 150*displaywidth)];
    setUpView.backgroundColor = [UIColor whiteColor];
    setUpView.layer.cornerRadius = 5;
    setUpView.layer.masksToBounds = YES;
    setUpView.hidden = YES;
    [self.view addSubview:setUpView];
    NSArray *imgUrlAry = @[@"fx",@"sc",@"jb"];
    NSArray *nameAry = @[@" 分享",@" 收藏",@" 举报"];
    for (int i = 0; i < imgUrlAry.count; i++)
    {
        UIButton *btn = [ZCControl createButtonWithFrame:CGRectMake(0, 50*displaywidth*i, 100*displaywidth, 49*displaywidth) ImageName:imgUrlAry[i] Target:self Action:@selector(closeSetUpAction:) Title:nameAry[i] Font:13.0];
        [btn setTitleColor:RGB(77, 77, 77) forState:UIControlStateNormal];
        btn.tag = 80+i;
        [setUpView addSubview:btn];
        if (i != 2)
        {
            UIView *lineAAView = [[UIView alloc] initWithFrame:CGRectMake(0, (i+1)*50*displaywidth-1*displaywidth, 100*displaywidth, 1*displaywidth)];
            lineAAView.backgroundColor = LinesColor;
            [setUpView addSubview:lineAAView];
            
        }
    }
    UIButton *deliverBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH - 70*displaywidth, SCREEN_HEIGHT - 70*displaywidth, 60*displaywidth, 60*displaywidth) ImageName:@"toudi" Target:self Action:@selector(onClickDeliverBtn) Title:nil Font:10];
    [self.view addSubview:deliverBtn];
}

- (void)closeSetUpAction:(UIButton *)btn
{
    if (btn.tag == 80)
    {
        //分享
        ShareManager *shareManager = [ShareManager shareToManager];
        if (_factoryModel.factoryImgs.count>0) {
            dailyImgModel *imgModel = _factoryModel.factoryImgs[0];
            shareManager.imgUrl = imgModel.url;
        } else {
            shareManager.imgUrl = @"";
        }
        shareManager.title = @"分享工厂";
        shareManager.descriptionStr = _factoryModel.user.name;
        shareManager.webUrl = @"http://m.moform.cn/#/";
    }
    else if (btn.tag == 81)
    {
        //收藏
        [self requestCollectAddOrRemove];
    }
    else
    {
        //举报
        FeedBackViewController *vc = [[FeedBackViewController alloc] init];
        vc.titleStr = @"举报";
        [self.navigationController pushViewController:vc animated:YES];
    }
}

//个人资料
- (void)requestGetUserInfo
{
    WEAKSELF;
    [HYBaseHandler requestGetUserInfoParmers:nil Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             weakSelf.userModel = [UserModel mj_objectWithKeyValues:obj[@"data"]];
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         
     }];
}

- (void)requestCollectAddOrRemove
{
    WEAKSELF;
    NSDictionary *dic = @{@"contractorId":[NSString stringWithFormat:@"%@",_companyID]};
    [HYBaseHandler requestCollectAddOrRemoveParmers:dic Success:^(id obj) {
        [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
    } failed:^(NSError *error) {

    }];
}

- (void)loadNewHeaderData
{
    if (_infoType == 0)
    {
        [_tableview.mj_header endRefreshing];
        [_tableview.mj_footer endRefreshing];
        return;
    }
    else if (_infoType == 1)
    {
        _leftPage = 0;
        [self requestRecruitmentNotice];
    }
    else
    {
        _rightPage = 0;
        [self requestEvaluateList];
        
    }
    
}

- (void)loadMoreFootData
{
    if (_infoType == 0)
    {
        [_tableview.mj_header endRefreshing];
        [_tableview.mj_footer endRefreshing];
        return;
    }
    else if (_infoType == 1)
    {
        _leftPage ++;
        [self requestRecruitmentNotice];
        
    }
    else
    {
        _rightPage ++;
        [self requestEvaluateList];
        
    }
}

- (void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBar.hidden = NO;
}


- (void)feedbackAction
{
    setUpView.hidden = !setUpView.hidden;
    
}

- (void)onClickCheckDetailMessageBtn:(UIButton *)sender {
    ProduceLineDetailViewController *produceLineDetailVC = [[ProduceLineDetailViewController alloc] init];
    ProductionLineModel *productionModel = _orderAry[sender.tag];
    produceLineDetailVC.ID = productionModel.ID;
    produceLineDetailVC.produceLineType = ALLPRODUCELINETYPE;
    [self.navigationController pushViewController:produceLineDetailVC animated:YES];
}

- (void)onClickSetBtn:(UIButton *)sender {
    SetUpTimeViewController *vc = [[SetUpTimeViewController alloc] init];
    ProductionLineModel *productionModel = _orderAry[sender.tag];
    vc.ID = productionModel.ID;
    vc.setupTimeType = ALLSETUPTIMETYPE;
    [self.navigationController pushViewController:vc animated:YES];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 2;
    }
    if (_infoType == 0)
    {
        return 1;
    }
    if (_infoType == 1)
    {
        return _orderAry.count;
    }
    if (_infoType == 2)
    {
        return _scoringAry.count;
    }
    
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0)
    {
        if (_factoryModel)
        {
            if (indexPath.row == 0)
            {
                UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 15*displaywidth, 60*displaywidth, 60*displaywidth) ImageName:@""];
                if (_factoryModel.factoryImgs.count > 0)
                {
                    dailyImgModel *imgModel = _factoryModel.factoryImgs[0];
                    [imgView sd_setImageWithURL:[NSURL URLWithString:imgModel.url]];
                }
                imgView.contentMode = UIViewContentModeScaleAspectFill;
                imgView.layer.masksToBounds = YES;
                [cell.contentView addSubview:imgView];
                UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(90*displaywidth, 10*displaywidth, SCREEN_WIDTH-105*displaywidth, 25*displaywidth) Font:16.0 Text:_factoryModel.user.name Color:RGB(77, 77, 77)];
                [cell.contentView addSubview:titlab];
                UILabel *namelab = [ZCControl createLabelWithFrame:CGRectMake(90*displaywidth, 35*displaywidth, SCREEN_WIDTH-105*displaywidth, 25*displaywidth) Font:13.0 Text:[NSString stringWithFormat:@"%@ %@",_factoryModel.linkman,_factoryModel.phone] Color:RGB(153, 153, 153)];
                [cell.contentView addSubview:namelab];
                
                UILabel *classLab = [ZCControl createLabelWithFrame:CGRectMake(90*displaywidth, 60*displaywidth, SCREEN_WIDTH-105*displaywidth, 25*displaywidth) Font:13.0 Text:[NSString stringWithFormat:@"%@/%@/%@",_factoryModel.user.province,_factoryModel.categorName,_factoryModel.productName] Color:RGB(153, 153, 153)];
                [cell.contentView addSubview:classLab];
                UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 89*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
                lineView.backgroundColor = LinesColor;
                [cell.contentView addSubview:lineView];
                
            }
            else
            {
                UILabel *addressLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, SCREEN_WIDTH-50*displaywidth, 45*displaywidth) Font:13.0 Text:_factoryModel.address Color:RGB(77, 77, 77)];
                [cell.contentView addSubview:addressLab];
                UIImageView *rightImgView = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH-35*displaywidth, 12.5*displaywidth, 15*displaywidth, 20*displaywidth) ImageName:@"dingwei"];
                rightImgView.contentMode = UIViewContentModeScaleAspectFit;
                [cell.contentView addSubview:rightImgView];
                UIView *lineBView = [[UIView alloc]initWithFrame:CGRectMake(0, 45*displaywidth, SCREEN_WIDTH, 5*displaywidth)];
                lineBView.backgroundColor = LinesColor;
                [cell.contentView addSubview:lineBView];
            }
        }
        
    }
    else
    {
        for (UIView *subView in cell.contentView.subviews)
        {
            [subView removeFromSuperview];
        }
        if (_infoType == 0)
        {
            cell.backgroundColor = BacksColor;
            UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(5*displaywidth, 5*displaywidth, SCREEN_WIDTH-10*displaywidth, 210*displaywidth)];
            whiteView.backgroundColor = [UIColor whiteColor];
            whiteView.layer.cornerRadius = 10;
            whiteView.layer.masksToBounds = YES;
            [cell.contentView addSubview:whiteView];
            UILabel *contentLab = [ZCControl createLabelWithFrame:CGRectMake(10*displaywidth, 10*displaywidth, SCREEN_WIDTH-30*displaywidth, 190*displaywidth) Font:13.0 Text:_factoryModel.intro Color:RGB(153, 153, 153)];
            CGRect bounds = [contentLab.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-30*displayheight, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(13.0+fontScale) forKey:NSFontAttributeName] context:nil];
            contentLab.frame = CGRectMake(10*displaywidth, 10*displaywidth, SCREEN_WIDTH-30*displaywidth, bounds.size.height+10*displaywidth);
            whiteView.frame = CGRectMake(5*displaywidth, 5*displaywidth, SCREEN_WIDTH-10*displaywidth, bounds.size.height+30*displaywidth);
            [whiteView addSubview:contentLab];
        }
        else if (_infoType == 1)
        {
//            cell.backgroundColor = BacksColor;
//            UIView *whiteview = [[UIView alloc] initWithFrame:CGRectMake(5*displaywidth, 5*displaywidth, SCREEN_WIDTH-10*displaywidth, 125*displaywidth)];
//            whiteview.backgroundColor = [UIColor whiteColor];
//            whiteview.layer.cornerRadius = 5;
//            whiteview.layer.masksToBounds = YES;
//            [cell.contentView addSubview:whiteview];
//            if (_orderAry.count > 0)
//            {
//                JobsModel *model = _orderAry[indexPath.row];
//                UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(20*displaywidth, 15*displaywidth, SCREEN_WIDTH-80*displaywidth, 25*displaywidth) Font:16.0 Text:model.name Color:RGB(129, 148, 196)];
//                [whiteview addSubview:nameLab];
//                UILabel *tostLab = [ZCControl createLabelWithFrame:CGRectMake(20*displaywidth, 40*displaywidth, SCREEN_WIDTH-80*displaywidth, 50*displaywidth) Font:13.0 Text:[NSString stringWithFormat:@"生产说明：\n%@",model.remark] Color:RGB(77, 77, 77)];
//                tostLab.lineBreakMode = NSLineBreakByTruncatingTail;
//                tostLab.adjustsFontSizeToFitWidth = NO;
//                [whiteview addSubview:tostLab];
//                UILabel *timeLab = [ZCControl createLabelWithFrame:CGRectMake(20*displaywidth, 90*displaywidth, SCREEN_WIDTH-80*displaywidth, 20*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@"项目工期：%@至%@",model.startDate,model.endDate] Color:RGB(128, 128, 128)];
//                [whiteview addSubview:timeLab];
//                UILabel *detailLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-125*displaywidth, 90*displaywidth, 100*displaywidth, 20*displaywidth) Font:13.0 Text:@"查看详情" Color:RGB(236, 165, 84)];
//                detailLab.textAlignment = NSTextAlignmentRight;
//                [whiteview addSubview:detailLab];
//
//                NSInteger statusNum = [model.status integerValue];
//                UIImageView *typeImgView = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH-45*displaywidth, 5*displaywidth, 40*displaywidth, 35*displaywidth) ImageName:@"jinxingzhong"];
//                typeImgView.contentMode = UIViewContentModeScaleAspectFit;
//                typeImgView.hidden = YES;
//                [cell.contentView addSubview:typeImgView];
//                if (statusNum == 2)
//                {
//                    typeImgView.hidden = NO;
//                }
//                if (statusNum == 3)
//                {
//                    typeImgView.hidden = NO;
//                    typeImgView.frame = CGRectMake(SCREEN_WIDTH-60*displaywidth, 35*displaywidth, 45*displaywidth, 45*displaywidth);
//                    typeImgView.image = [UIImage imageNamed:@"yiwancheng"];
//                }
//            }
            cell.backgroundColor = BacksColor;
            UIView *whiteview = [[UIView alloc] initWithFrame:CGRectMake(5*displaywidth, 5*displaywidth, SCREEN_WIDTH-10*displaywidth, 120*displaywidth)];
            whiteview.backgroundColor = [UIColor whiteColor];
            whiteview.layer.cornerRadius = 5;
            whiteview.layer.masksToBounds = YES;
            [cell.contentView addSubview:whiteview];
            UIButton *setBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH - 36, 18*displaywidth, 20*displaywidth, 20*displaywidth) ImageName:@"shez" Target:self Action:@selector(onClickSetBtn:) Title:nil Font:15];
            setBtn.tag = indexPath.section;
            setBtn.enabled = NO;
            [cell.contentView addSubview:setBtn];
            UIButton *checkDetailMessageBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH - 100*displaywidth - 16, 89*displaywidth, 100*displaywidth, 20*displaywidth) ImageName:nil Target:self Action:@selector(onClickCheckDetailMessageBtn:) Title:nil Font:15];
            [checkDetailMessageBtn setTitle:@"查看详情" forState:UIControlStateNormal];
            [checkDetailMessageBtn setTitleColor:UIColorHexValue(0xECA554) forState:UIControlStateNormal];
            checkDetailMessageBtn.tag = indexPath.section;
            [cell.contentView addSubview:checkDetailMessageBtn];
            cell.layer.cornerRadius = 10;
            cell.layer.masksToBounds = YES;
            ProductionLineModel *productionModel = _orderAry[indexPath.section-1];
            ProduceKindModel *produceKindModel = productionModel.category;
            UIImageView *catogoryImageView = [ZCControl createImageViewWithFrame:CGRectMake(18*displaywidth, 46*displaywidth, 17*displaywidth, 17*displaywidth) ImageName:@"chanpingleirong"];
            [cell.contentView addSubview:catogoryImageView];
            UIImageView *pointImageView = [ZCControl createImageViewWithFrame:CGRectMake(139*displaywidth, 46*displaywidth, 17*displaywidth, 17*displaywidth) ImageName:@"jeidian"];
            [cell.contentView addSubview:pointImageView];
            UILabel *produceLineNameLabel = [ZCControl createLabelWithFrame:CGRectMake(18*displaywidth, 18*displaywidth, 100*displaywidth, 21*displaywidth) Font:15.0 Text:productionModel.name Color:ThemeColor];
            [cell.contentView addSubview:produceLineNameLabel];
            
            UIImageView *statusImageView = [ZCControl createImageViewWithFrame:CGRectMake(118*displaywidth, 19*displaywidth, 20*displaywidth, 20*displaywidth) ImageName:@""];
            if (productionModel.free && [productionModel.free isEqual:@"1"] && ![productionModel.free isKindOfClass:[NSNull class]]) {
                statusImageView.image = [UIImage imageNamed:@"xian"];
            } else if (productionModel.free && [productionModel.free isEqual:@"0"] && ![productionModel.free isKindOfClass:[NSNull class]]) {
                statusImageView.image = [UIImage imageNamed:@"manyuan"];
            }
            [cell.contentView addSubview:statusImageView];
            UILabel *produceLineKindLabel = [ZCControl createLabelWithFrame:CGRectMake(50*displaywidth, 48*displaywidth, 87*displaywidth, 13.5*displaywidth) Font:14.0 Text:produceKindModel.name Color:UIColorHexValue(0x4D4D4D)];
            [cell.contentView addSubview:produceLineKindLabel];
            UILabel *produceLinePointLabel = [ZCControl createLabelWithFrame:CGRectMake(171*displaywidth, 48*displaywidth, 70*displaywidth, 13.5*displaywidth) Font:14.0 Text:[NSString stringWithFormat:@"%@个结点", productionModel.galleryful] Color:UIColorHexValue(0x4D4D4D)];
            [cell.contentView addSubview:produceLinePointLabel];
            
            NSArray *tempArr = productionModel.machines;
            NSString *nameStr = @"";
            for (int i = 0; i < tempArr.count; i++) {
                ProduceMachinesModel *model = tempArr[i];
                if (i == tempArr.count - 1) {
                    nameStr = [NSString stringWithFormat:@"%@%@", nameStr, model.machine.name];
                } else {
                    nameStr = [NSString stringWithFormat:@"%@%@、", nameStr, model.machine.name];
                }
            }
            nameStr = [NSString stringWithFormat:@"生产设备:%@", nameStr];
            UILabel *produceEquipmentLabel = [ZCControl createLabelWithFrame:CGRectMake(16*displaywidth, 78*displaywidth, 229*displaywidth, 31*displaywidth) Font:14.0 Text:nameStr Color:UIColorHexValue(0x999999)];
            [cell.contentView addSubview:produceEquipmentLabel];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
        }
        else
        {
            if (_scoringAry.count > 0)
            {
                ScoringModel *model = _scoringAry[indexPath.row];
                UIView *lineBview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1*displaywidth)];
                lineBview.backgroundColor = LinesColor;
                [cell.contentView addSubview:lineBview];
                UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(10*displaywidth, 15*displaywidth, 40*displaywidth, 40*displaywidth) ImageName:@"toux"];
                imgView.layer.cornerRadius = 20*displaywidth;
                imgView.layer.masksToBounds = YES;
                if (model.user.headImg.length > 0)
                {
                    [imgView sd_setImageWithURL:[NSURL URLWithString:model.user.headImg] placeholderImage:[UIImage imageNamed:@"toux"]];
                }
                [cell.contentView addSubview:imgView];
                NSInteger typeNum = [model.user.type integerValue];
                NSString *typeName = @"雇主";
                UIColor *backColor = RGB(238, 103, 94);
                if (typeNum == 2)
                {
                    typeName = @"厂家";
                    backColor = ThemeColor;
                }
                if (typeNum == 3)
                {
                    typeName = @"工人";
                    backColor = ThemeColor;
                }
                UILabel *typrLab = [ZCControl createLabelWithFrame:CGRectMake(60*displaywidth, 15*displaywidth, 30*displaywidth, 15*displaywidth) Font:10.0 Text:typeName Color:[UIColor whiteColor]];
                typrLab.backgroundColor = backColor;
                typrLab.textAlignment = NSTextAlignmentCenter;
                typrLab.layer.cornerRadius = 2;
                typrLab.layer.masksToBounds = YES;
                [cell.contentView addSubview:typrLab];
                
                UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(105*displaywidth, 10*displaywidth, SCREEN_WIDTH-215*displaywidth, 25*displaywidth) Font:12.0 Text:model.user.name Color:RGB(153, 153, 153)];
                [cell.contentView addSubview:nameLab];
                
                UILabel *contenLab = [ZCControl createLabelWithFrame:CGRectMake(105*displaywidth, 35*displaywidth, SCREEN_WIDTH-120*displaywidth, 35*displaywidth) Font:14.0 Text:model.user.name Color:RGB(77, 77, 77)];
                [cell.contentView addSubview:contenLab];
                
                CDZStarsControl *starsControl = [CDZStarsControl.alloc initWithFrame:CGRectMake(SCREEN_WIDTH-110*displaywidth, 10*displayheight, 100*displaywidth , 25*displayheight) stars:5 starSize:CGSizeMake(20*displayheight, 20*displayheight) noramlStarImage:[UIImage imageNamed:@"huixx"] highlightedStarImage:[UIImage imageNamed:@"hongxx"]];
                starsControl.delegate = self;
                starsControl.allowFraction = YES;
                starsControl.score = [model.grade floatValue];
                [cell.contentView addSubview:starsControl];
                
            }
        }
        
    }
    
    return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row == 1)
    {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"请选择地图" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        WEAKSELF;
        [alertVC addAction:[UIAlertAction actionWithTitle:@"用iPhone自带地图导航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [weakSelf pushIphoneMap];
        }]];
        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]])
        {
            [alertVC addAction:[UIAlertAction actionWithTitle:@"用百度地图导航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
 
                        CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([weakSelf.factoryModel.user.lat floatValue], [weakSelf.factoryModel.user.lng floatValue]);
                        NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=gcj02",coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
            }]];
        }
        if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]){
        
            [alertVC addAction:[UIAlertAction actionWithTitle:@"用高德地图导航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
            {
                CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([weakSelf.factoryModel.user.lat floatValue], [weakSelf.factoryModel.user.lng floatValue]);
                NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%f&lon=%f&dev=0&style=2",@"魔招",@"MagicZhaoUrl",coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
            }]];
        }
 
        [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            
        }]];
        
        
        [self presentViewController:alertVC animated:YES completion:nil];

    }
    if (_infoType == 1 && indexPath.section == 1)
    {
//        JobsModel *model = _orderAry[indexPath.row];
//        WorkDetailsViewController *vc = [[WorkDetailsViewController alloc] init];
//        vc.projectID = model.ID;
//        vc.deatilType = 1;
//        [self.navigationController pushViewController:vc animated:YES];
        ProduceLineDetailViewController *produceLineDetailVC = [[ProduceLineDetailViewController alloc] init];
        produceLineDetailVC.produceLineType = ALLPRODUCELINETYPE;
        ProductionLineModel *productionModel = _orderAry[indexPath.section];
        produceLineDetailVC.ID = productionModel.ID;
        [self.navigationController pushViewController:produceLineDetailVC animated:YES];
    }
    if (_infoType == 2 && indexPath.section == 1)
    {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"请选择举报理由" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        
        [alertVC addAction:[UIAlertAction actionWithTitle:@"低俗脏话" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            FeedBackViewController *vc = [[FeedBackViewController alloc] init];
            vc.titleStr = @"举报";
            [self.navigationController pushViewController:vc animated:YES];
        }]];
        
        [alertVC addAction:[UIAlertAction actionWithTitle:@"营销诈骗" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            FeedBackViewController *vc = [[FeedBackViewController alloc] init];
            vc.titleStr = @"举报";
            [self.navigationController pushViewController:vc animated:YES];
        }]];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"其他理由" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            FeedBackViewController *vc = [[FeedBackViewController alloc] init];
            vc.titleStr = @"举报";
            [self.navigationController pushViewController:vc animated:YES];
        }]];
        
        [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            
        }]];
        
        
        [self presentViewController:alertVC animated:YES completion:nil];
    }
}

- (void)pushIphoneMap
{
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com/"]]){
        //MKMapItem 使用场景: 1. 跳转原生地图 2.计算线路
        MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
        
        //地理编码器
        CLGeocoder *geocoder = [[CLGeocoder alloc] init];
        //我们假定一个终点坐标，上海嘉定伊宁路2000号报名大厅:121.229296,31.336956
        [geocoder geocodeAddressString:_factoryModel.address completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
            CLPlacemark *endPlacemark  = placemarks.lastObject;
            
            //创建一个地图的地标对象
            MKPlacemark *endMKPlacemark = [[MKPlacemark alloc] initWithPlacemark:endPlacemark];
            //在地图上标注一个点(终点)
            MKMapItem *endMapItem = [[MKMapItem alloc] initWithPlacemark:endMKPlacemark];
            
            //MKLaunchOptionsDirectionsModeKey 指定导航模式
            //NSString * const MKLaunchOptionsDirectionsModeDriving; 驾车
            //NSString * const MKLaunchOptionsDirectionsModeWalking; 步行
            //NSString * const MKLaunchOptionsDirectionsModeTransit; 公交
            [MKMapItem openMapsWithItems:@[currentLocation, endMapItem]
                           launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
            
        }];
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *myView = [[UIView alloc] init];
    if (section == 1)
    {
        myView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 45*displayheight);
        myView.backgroundColor = [UIColor whiteColor];
        NSArray *titArray = @[@"工厂介绍",@"工厂产线",@"评价"];
        CGFloat width = (SCREEN_WIDTH-2)/3;
        for (int i = 0; i < titArray.count; i++)
        {
            UIButton *btn = [ZCControl createButtonWithFrame:CGRectMake((width+1)*i, 0, width, 44*displayheight) ImageName:nil Target:self Action:@selector(closeInfoAction:) Title:titArray[i] Font:16.0];
            btn.backgroundColor = [UIColor whiteColor];
            [btn setTitleColor:RGB(77, 77, 77) forState:UIControlStateNormal];
            if (i == _infoType)
            {
                [btn setTitleColor:ThemeColor forState:UIControlStateNormal];
            }
            btn.tag = 20+i;
            [myView addSubview:btn];
            if (i != 2)
            {
                UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(width+(width+1)*i, 12.5*displayheight, 1, 20*displayheight)];
                lineview.backgroundColor = RGB(153, 153, 153);
                [myView addSubview:lineview];
            }
            
        }
        UIView *lineBV = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/3*_infoType+30*displaywidth, 44*displayheight, SCREEN_WIDTH/3-60*displaywidth, 1*displayheight)];
        lineBV.backgroundColor = ThemeColor;
        [myView addSubview:lineBV];
        lineBottomV = lineBV;
    }
    
    return myView;
}

- (void)onClickDeliverBtn {
    if (![LTools storageForKey:SERVER_IsLogin])
    {
        LoginOrRegisterViewController *vc = [[LoginOrRegisterViewController alloc] init];
        HYNavBaseViewController *nav = [[HYNavBaseViewController alloc] initWithRootViewController:vc];
        [self presentViewController:nav animated:YES completion:nil];
        return;
    }
    if (_userModel) {
        if ([_userModel.identityId integerValue] == 0 || [_userModel.identityId integerValue] == -1) {
            //            [LTools showMBProgressWithText:@"认证成功后,才可发布需求" addToView:self.view];
            //            return;

            alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否前往认证?" preferredStyle:UIAlertControllerStyleAlert];
            WEAKSELF;
            // 添加按钮
            __weak typeof(alert) weakAlert = alert;
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                [_timer invalidate];
                _timer = nil;
            }]];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"前往" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                _isClick = YES;
                AuthenticationViewController *authenVC = [[AuthenticationViewController alloc] init];
                [self.navigationController pushViewController:authenVC animated:YES];
            }]];
            [self presentViewController:alert animated:YES completion:nil];
            
            _timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(gotoAuthen) userInfo:Nil repeats:YES];
            
        } else {
            ProjectEditViewController *projectVC = [[ProjectEditViewController alloc] init];
            projectVC.contractorDic = @{@"id" : _factoryModel.ID};
            [self.navigationController pushViewController:projectVC animated:YES];
        }
    }
    
}

- (void)gotoAuthen {
    if (!_isClick) {
        [self dismissViewControllerAnimated:alert completion:nil];
        AuthenticationViewController *authenVC = [[AuthenticationViewController alloc] init];
        [self.navigationController pushViewController:authenVC animated:YES];
    }
}

- (void)closeInfoAction:(UIButton *)btn
{
    _infoType = btn.tag-20;
    if (btn.tag == 20)
    {
        //工厂介绍
    }
    else if (btn.tag == 21)
    {
        //招工告示
    }
    else
    {
        //评价
    }
    
    lineBottomV.frame = CGRectMake(SCREEN_WIDTH/3*_infoType+30*displaywidth, 44*displayheight, SCREEN_WIDTH/3-60*displaywidth, 1*displayheight);
    [self.tableview reloadData];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 0;
    }
    
    return 45*displayheight;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            return 90*displaywidth;
        }
        else
        {
            return 50*displaywidth;
        }
    }
    if (_infoType == 0)
    {
        if (_factoryModel)
        {
            CGRect bounds = [_factoryModel.intro boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-30*displayheight, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:NormalFontWithSize(13.0+fontScale) forKey:NSFontAttributeName] context:nil];
            return bounds.size.height + 40*displayheight;
        }
        return 220*displaywidth;
    }
    else if (_infoType == 1)
    {
        return 125*displaywidth;
    }
    else
    {
        return 70*displaywidth;
    }
}

- (void)requestContractorDetail
{
    WEAKSELF;
    NSDictionary *dic = @{@"id":[NSString stringWithFormat:@"%@",_companyID]};
    [HYBaseHandler requestContractorDetailParmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            weakSelf.factoryModel = [FactoryModel mj_objectWithKeyValues:obj[@"data"]];
            [weakSelf requestEvaluateList];
            dispatch_async(dispatch_get_main_queue(), ^{
                if (weakSelf.factoryModel.factoryImgs.count > 0)
                {
                    NSMutableArray *imgAry = [NSMutableArray arrayWithCapacity:0];
                    for (dailyImgModel *model in weakSelf.factoryModel.factoryImgs)
                    {
                        [imgAry addObject:model.url];
                    }
                    weakSelf.cycleScrollView.imageURLStringsGroup = imgAry;
                }
                
                [weakSelf.tableview reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

- (void)requestRecruitmentNotice
{
    WEAKSELF;
    NSDictionary *dic = @{@"page":[NSString stringWithFormat:@"%ld",_leftPage],
                          @"contractor.id":[NSString stringWithFormat:@"%@",_companyID]
                          };
    [HYBaseHandler requestAllProductionLineParmers:dic Success:^(id obj) {
        [weakSelf.tableview.mj_header endRefreshing];
        [weakSelf.tableview.mj_footer endRefreshing];
        if ([obj server_Getcodecheck])
        {
//            NSArray *orderArray = [JobsModel mj_objectArrayWithKeyValuesArray:obj[@"data"][@"content"]];
            NSArray *orderArray = [ProductionLineModel mj_objectArrayWithKeyValuesArray:obj[@"data"][@"content"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                if (weakSelf.leftPage == 0)
                {
                    [weakSelf.orderAry removeAllObjects];
                }
                [weakSelf.orderAry addObjectsFromArray:orderArray];
                [weakSelf.tableview reloadData];
            });
            
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        [weakSelf.tableview.mj_header endRefreshing];
        [weakSelf.tableview.mj_footer endRefreshing];
    }];
}

- (void)requestEvaluateList
{
    if (!_factoryModel)
    {
        return;
    }
    WEAKSELF;
    NSDictionary *dic = @{@"page":[NSString stringWithFormat:@"%ld",_rightPage],
                          @"target.id":[NSString stringWithFormat:@"%@",_factoryModel.user.ID]
                          };
    [HYBaseHandler requestEvaluateListParmers:dic Success:^(id obj) {
        [weakSelf.tableview.mj_header endRefreshing];
        [weakSelf.tableview.mj_footer endRefreshing];
        if ([obj server_Getcodecheck])
        {
            NSArray *scoringArray = [ScoringModel mj_objectArrayWithKeyValuesArray:obj[@"data"][@"content"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                if (weakSelf.rightPage == 0)
                {
                    [weakSelf.scoringAry removeAllObjects];
                }
                [weakSelf.scoringAry addObjectsFromArray:scoringArray];
                [weakSelf.tableview reloadData];
            });
            
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        [weakSelf.tableview.mj_header endRefreshing];
        [weakSelf.tableview.mj_footer endRefreshing];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
